#include <stdio.h>
#include <stdlib.h>
#include "struct.h" 
#define _CRT_SECURE_NO_WARNINGS

typedef struct node
{ 
	ElemType data;
	struct node *next;
}Node,*LinkList;

status InitList(LinkList & L,int n)
{
	ElemType e;
	LinkList q,r;
	L = (LinkList)malloc(sizeof Node);
	if (!L)
		exit(OVERFLOW);
	L->next = NULL;
	r = L;
	for (int i = 0; i < n; i++)
	{
		q = (LinkList)malloc(sizeof Node);
		scanf("%d", &e);
		q->data = e;
		r->next = q;
		r = q;
	}
	r->next = NULL;
	return OK;
}

status VisitList(LinkList L,void(*visitFun)(Node *p))
{
	LinkList q;
	q = L->next;
	while (q)
	{
		visitFun(q);
		q = q->next;
	}
	return OK;
}

void visit(Node* p)
{
	printf("%2d", p->data);
}


status InsertList(LinkList& L, int i, ElemType e)
{
	int j = 0;
	LinkList p = L;
	LinkList s;
	while (p && j < i - 1)
	{
		p = p->next;
		++j;
	}
	if (!p || j > i - 1)
		return ERROR;
	s = (LinkList)malloc(sizeof Node);
	s->data = e;
	s->next = p->next;
	p->next = s;
	return OK;
}

int main()
{
	LinkList L;
	InsertList(L, 2, 9);
	VisitList(L, visit);
}